#pragma once
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include "Student.h"

using namespace std;

class StudentRegister
{
private:
	//karakteristisk data
	vector<Student> vsRegister;

public:
	//konstruktorer
	StudentRegister(void);

	//medlemsfunktioner
	void Add(Student student)
	{
		vsRegister.push_back(student);
	}
	string List()
	{
		ostringstream oss;
		for (auto &s : vsRegister)
		{
			oss << s << endl;
		}

		return oss.str();
	}
	void WriteToFile(string fileName)
	{
		ofstream fout(fileName);
		for (auto &s : vsRegister)
		{
			fout << "Student:" << s << endl;
		}
		fout.close();
	}
	void ReadFromFile(string fileName)
	{
		string str, strRow;
		ifstream fin;

		fin.open(fileName);
		vsRegister.clear();

		while (getline(fin, strRow))
		{
			istringstream iss(strRow);
			getline(iss, str, ':');
			if (str.compare("Student") == 0)
			{
				Student s;
				iss >> s;
				vsRegister.push_back(s);
			}
		}
		fin.close();
	}

	//destruktor
	~StudentRegister(void);
};

